#include <iostream>
#include <cstring>
#include <vector>

using namespace std;

//100%
class Solution
{
  public:
    vector<int> findAnagrams(string s, string p)
    {
        vector<int> myVector;
        if (s.size() < p.size())
            return myVector;
        int freq1[26] = {0};
        int freq2[26] = {0};
        memset(freq1, 0, sizeof(freq1));
        memset(freq2, 0, sizeof(freq2));
        for (int i = 0; i < p.size(); ++i)
        {
            freq1[p[i] - 'a']++;
            freq2[s[i] - 'a']++;
        }
        if (eql(freq1, freq2))
        {
            myVector.push_back(0);
        }
        int l = 0, r = p.size() - 1;
        while (r < s.size() - 1)
        {
            freq2[s[l++] - 'a']--;
            freq2[s[++r] - 'a']++;
            if (eql(freq1, freq2))
            {
                myVector.push_back(l);
            }
        }
        return myVector;
    }
    bool eql(int *a, int *b)
    {
        for (int i = 0; i < 26; i++)
        {
            if (a[i] != b[i])
                return false;
        }
        return true;
    }
};

int main()
{
    string s = "aaaaaaa", p = "a";
    vector<int> myVector(Solution().findAnagrams(s, p));
    for (int i = 0; i < myVector.size() - 1; ++i)
    {
        cout << myVector[i] << " ";
    }
    cout << myVector[myVector.size() - 1] << endl;
    return 0;
}
